package com.prs.util;

import java.io.File;
import javax.swing.ImageIcon;
import org.prs.persistence.PhotoDatabasePersitenceManager;

public class FileUtil {
    static PhotoDatabasePersitenceManager persistPhoto=new PhotoDatabasePersitenceManager();
    public static String getNewPhotoFileName(String mimeType){
        String newFileName="photo";
        newFileName+=persistPhoto.getNewPhotoId();
        if(mimeType.equals("image/jpeg")){
            return  newFileName+".jpeg";
        }else if(mimeType.equals("image/png")){
            return  newFileName+".png";
        }else if(mimeType.equals("image/gif")){
            return  newFileName+".gif";
        }else if(mimeType.equals("image/svg+xml")){
            return  newFileName+".svg";
        }else if(mimeType.equals("image/jpg")){
            return  newFileName+".jpg";
        }
        return newFileName;
    }
     public static boolean isAnImage(String mimeType){
        
        
        if(mimeType.equals("image/jpeg")){
            return true;
        }else if(mimeType.equals("image/png")){
            return true;
        }else if(mimeType.equals("image/gif")){
            return true;
        }else if(mimeType.equals("image/svg+xml")){
            return true;
        }else if(mimeType.equals("image/jpg")){
            return true;
        }
        else{
            return false;
        }
    }
    public static int getPhotoWidth(String path){
        ImageIcon image=new ImageIcon(path);
        if(image.getIconHeight()>200||image.getIconWidth()>200){
            return (image.getIconWidth()*200)/(image.getIconHeight()+image.getIconWidth());
        }
        return image.getIconWidth();
    }
    public static int getPhotoHeight(String path){
        ImageIcon image=new ImageIcon(path);
        if(image.getIconHeight()>200||image.getIconWidth()>200){
            return (image.getIconHeight()*200)/(image.getIconHeight()+image.getIconWidth());
        }
        return image.getIconHeight();
    }


}
